<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="_session_check.jsp" %>
<%@ page import="com.shopping.modean.*"%>
<%@ page import="com.shopping.service.*"%>
<%@ page import="com.shopping.util.*"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%
    //获取pid = 0 的分类
	CategoryService categoyService = new CategoryService();
	List<Category> categorys = categoyService.list(0);
%>

<!DOCTYPE html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分类列表</title>

<style type="text/css">
 * {
 	margin: 0;
 	padding: 0;
 }

</style>

<script type="text/javascript">
	function showDialog() {
		var dialog = document.getElementById("dialogDiv");
		dialog.style.display = "block";
	}
	
	function cancel() {
		var dialog = document.getElementById("dialogDiv");
		dialog.style.display = "none";
	}

</script>

</head>

<body>
  
  <div>
    <div style="width:783px;margin: 15px auto;">
		<input style="height: 30px;padding-left: 5px;" type="text" placeholder="输入名称或描述"/>
		<button style="height: 34px;" onclick="">&nbsp;搜&nbsp;索&nbsp;</button>   
		<button style="height: 34px;" onclick="showDialog()">&nbsp;添&nbsp;加&nbsp;</button>  
    </div>
  	<table border="1" style="border-collapse:collapse;text-align: center;margin: 0 auto;">
	  	<tr height="60px">
	  		<td width="50px">ID</td>
	  		<td width="100px">分类名称</td>
	  		<td width="150px">分类描述</td>
	  		<td width="75px">PID</td>
	  		<td width="75px">级别</td>
	  		<td width="75px">子类个数</td>
	  		<td width="250px">操作</td>
	  	</tr>
	    
	    <%
	    	for(Category c : categorys) {
	    %>
	    <tr height="60px">
	  		<td><%=c.getId() %></td>
	  		<td><%=c.getName() %></td>
	  		<td><%=c.getDescr() %></td>
	  		<td><%=c.getPid() %></td>
	  		<td><%=c.getGrade() %></td>
	  		<td align="center">
	  		  <a href="category_list_sub.jsp?pid=<%=c.getId() %>"><%=c.getLeafSize() %></a>
	  		</td>
	  		<td>
	  		  <a href="category_update.jsp?id=<%=c.getId() %>">修改</a>
	  		  <span>|</span>
	  		  <a href="category_delete.jsp?action=categoryDelete&id=<%=c.getId() %>">删除</a>
	  		  <span>|</span>
	  		  <a href="category_add.jsp?pid=<%=c.getId() %>">添加子节点</a>
	  		</td>
	  	</tr>
	     <% } %>
	 </table>
  </div>
  
  <div id = "dialogDiv" style="background-color:rgba(63, 63, 63, 0.7);display: none;width:100vw;height:100vh;position: fixed;top:0;left:0;">
	<div>
		<form method="post" id="category_add" name="category_add" action="category_add.jsp" 
		      style="background-color: #ffffff;position: absolute;left:0;top:0;right:0;bottom:0;width:800px;height: 500px;margin: auto; " >
		    <input type="hidden" name="action" value="categoryAdd" />
		    <input type="hidden" name="pid" value="" />
			<table class="tableborder" align="center" cellpadding="4" cellspacing="1" width="97%">
		        <tr>
		           <td>&nbsp;</td>
		        </tr>
		        <tr>
		           <td>&nbsp;</td>
		        </tr>
		        <tr>
		          <td class="altbg1" width="21%"><span style="color:red">*</span>分类名称:</td>
		          <td class="altbg2">
		            <input id="name" name="name" size="25" maxlength="25" type="text"> 
		            <span id="usermsg"></span>
		          </td>
		        </tr>
				
		        <tr>
		          <td class="altbg1" valign="top">分类描述:</td>
		          <td class="altbg2"><textarea name="descr" cols="60" rows="5" id="descr"></textarea></td>
		        </tr>
		        <tr>
		          <td class="altbg1"></td>
		          <td class="altbg2">
		          	<input name="regsubmit" value="提 &nbsp; 交" type="submit">
		          	<input name="listCategory" value="查看分类列表" type="button" onClick="toListCategory()">
		          	<input name="listCategory" value="取消" type="button" onClick="cancel()">
		          </td>
		        </tr>
		      </tbody>
		    </table>
	  </form>
	</div>  	
  </div>

  
  

</body>
</html>